import { camelize, snakeCase } from "@/utils";

// 转换对象的 key格式
const convertObjKey = <T extends object>(obj: T, flog: "camelize" | "snakeCase"): T => {
  const result: any = {};
  for (const key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      let newKey;
      if (flog === "snakeCase") {
        newKey = snakeCase(key);
      } else if (flog === "camelize") {
        newKey = camelize(key);
      }
      result[newKey as string] = obj[key];
    }
  }
  return result;
};

export { convertObjKey };
